package sdk.webview.fmc.com.fmcsdk.manager;

import android.app.ActivityManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.text.TextUtils;

import java.util.List;

/**
 * Created by  on 2018/7/12.
 * 设置SDK的一些基本配置
 */
public class FMCManager {
    private static FMCManager instance;
    private static SharedPreferences sharedPreferences;

        public static synchronized FMCManager getInstance(){
        if (instance == null) {
            instance = new FMCManager();
        }
        return instance;
    }
    public  FMCManager init(Context context){
            FMSdk.call(null, new FMSdk.LoginFMCallBack() {
                @Override
                public void loginStatus(int status) {

                }
            });
            FMSdk.push(null, new FMSdk.PushCallBack() {
                @Override
                public void pushStatus(int status) {

                }
            });
            FMSdk.getMessageCount(null, new FMSdk.TaskCountCallBack() {
                @Override
                public void getMessageCountSuccess(int count) {

                }

                @Override
                public void getMessageCountError(int status) {

                }
            });
        sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
        return this;
    }

//    /**
//     * 图片上传到服务器的路径
//     * @param serverPath
//     * @return
//     */
//    public  FMCManager setUploadImageServerPath(String serverPath){
//        sharedPreferences.edit().putString(Constant.UPLOAD_IMAGE_SERVER_PATH,serverPath).apply();
//        return this;
//    }


    /**

     * 判断一个Activity是否正在运行

     * @param pkg

     * @param cls

     * @param context

     * @return

     */

    public static boolean isClsRunning(String pkg, String cls, Context context) {

        ActivityManager am =(ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);

        List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);

        ActivityManager.RunningTaskInfo task = tasks.get(0);

        if (task != null) {

            return TextUtils.equals(task.topActivity.getPackageName(), pkg) && TextUtils.equals(task.topActivity.getClassName(), cls);

        }

        return false;

    }
}
